﻿using RPAVIEW.util;
using RPAVIEW.views.controlLibrary;
using RPAVIEW.views.OtherPages;
using SUNRPA.CONTROLS.IMPL.domain.flowItemParam;
using SUNRPA.CONTROLS.IMPL.util;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;

namespace RPAVIEW.views.EditPage.flows.CloseExcelN {
    /// <summary>
    /// Input.xaml 的交互逻辑
    /// </summary>
    public partial class Input:BaseParamViewAction{
        public Input() {
            InitializeComponent();
        }

        public override void UpdateSource() {
            this.closeOper.GetBindingExpression(System.Windows.Controls.ComboBox.SelectedIndexProperty).UpdateSource();
            this.closeObjName.GetBindingExpression(SelVarTextBox.text).UpdateSource();
            this.beforeClose.GetBindingExpression(System.Windows.Controls.ComboBox.SelectedIndexProperty).UpdateSource();
            this.saveAsPath.GetBindingExpression(SelVarTextBox.text).UpdateSource();
            this.coverIfExist.GetBindingExpression(System.Windows.Controls.CheckBox.IsCheckedProperty).UpdateSource();
        }

        private void CloseWayChange(object sender, SelectionChangedEventArgs e) {
            int closeWay = this.closeOper.SelectedIndex;
            if(closeWay == 0) {
                this.excelObjRow.Height = GridLength.Auto;
                this.beforeCloseRow.Height = GridLength.Auto;
                BeforeWayChange(sender, e);
            } else { 
                 this.excelObjRow.Height = new GridLength(0);
                 this.beforeCloseRow.Height = new GridLength(0);
                 this.savePathRow.Height = new GridLength(0);
                 this.coverRow.Height = new GridLength(0);
            }
        }

        private void BeforeWayChange(object sender, SelectionChangedEventArgs e) {
            int beforeWay = this.beforeClose.SelectedIndex;
            if(beforeWay == 0 || beforeWay == 2) { 
                this.savePathRow.Height = new GridLength(0);
                this.coverRow.Height = new GridLength(0);
            } else { 
                this.savePathRow.Height = GridLength.Auto;
                this.coverRow.Height = GridLength.Auto;
            }
        }

        private void SelectSavePath(object sender, RoutedEventArgs e) {
            SaveFileDialog saveDialog =  FileUtil.OpenSaveFileDialog(".xls;.xlsx|*.xls;*.xlsx");
            saveDialog.FileName = "WorkBook.xlsx";
            saveDialog.ShowDialog();
            this.saveAsPath.Text = saveDialog.FileName;
        }
    }
}
